﻿using Commonality.DAL.MySQL;
using Commonality.DAL.WZS_SFCS;
using Commonality.DAL.WZS_SFCS;
using Commonality.Model;
using Commonality.Model.Classify;
using Commonality.Model.PLCControl;
using Commonality.Model.Xml;
using MathNet.Numerics.LinearAlgebra.Double;
using Merge.BLL;
using Merge.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using TextEditing;
using static Commonality.DAL.MySQL.MySqlFunction;

namespace WZS_Auto_Classifying_Merge
{
    public partial class DebugForm : Form
    {
        public static DebugForm debugForm;
        //static ClassifyEngine classModel = new ClassifyEngine();
        public DebugForm()
        {
            InitializeComponent();
            debugForm = this;
        }

        private void DebugForm_Load(object sender, EventArgs e)
        {
            //DenseMatrix MEigenvector = DenseMatrix.OfArray(new[,] { { 1.0}, { 2.0}, { 3.0}, { 4.0 } });
            //DenseMatrix a = new DenseMatrix(1,1);
            //MEigenvector.SubMatrix(0, 1, 0, 1);




        }

        private void AddPNButt_Click(object sender, EventArgs e)
        {
            //classModel.ConstructionClassModelFunc_AddPNi("LIEBESKIND");
            //var c = classModel.ClassModels;
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            ClassModel classModel = new ClassModel();
            ProductCellData productCellData = new ProductCellData() { usn = CTextCreate.GetRandomString(11, true, false, true, false, ""), usnInfo = new string[2] { "", CTextCreate.GetRandomString(11, true, false, true, false, "") }, bin = new string[1] { "" } };

            //
            //MySqlFunction.PackageOrientation.PackageOrientation_INSERT(productCellData.usn, 0, "OK");
            MySqlFunction.TrayCellDataList.TrayCellDataList_INSERT(productCellData, productCellData);
            //

            //Classify.classifyEngineA.NewEigenvectorExtract(productCellData, ref classModel);
            string Eigenvector = classModel.StringEigenvector;
            MySqlFunction.TrayCellDataList.TrayCellDataList_Eigenvector_UPDATE(productCellData.usn, productCellData.usn, ref Eigenvector);
            //Log4Net.MsgInfo(Classify.classifyEngineA.ClassModels.Count);

            Log4Net.MsgInfo("识别类型：" + classModel.StringEigenvector);
        }

        private void Button2_Click(object sender, EventArgs e)
        {
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            //Caver.CaveA11.ProgrammeWarehousing(CTextCreate.GetRandomString(11, true, false, true, false, ""), CTextCreate.GetRandomString(11, true, false, true, false, ""));
        }

        private void Button4_Click(object sender, EventArgs e)
        {
            //Caver.CaveA11
        }

        private void Button5_Click(object sender, EventArgs e)
        {
            Caver.CaveA11.DataClearance();
        }

        private void Button6_Click(object sender, EventArgs e)
        {
            //Log4Net.MsgInfo(CPLCControl.LAD_GetDblCell(PLC.dDestination_A2));
            //if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A2) == 0)
            //{
            //    Log4Net.MsgInfo("A2模组空闲");
            //}
            //else
            //{
            //    Log4Net.MsgInfo("A2模组忙");
            //}

        }

        private void Button7_Click(object sender, EventArgs e)
        {
            //CPLCControl.LAD_SetDblCell(PLC.dDestination_A2, 4);
        }

        private void Button8_Click(object sender, EventArgs e)
        {
            //List<string> data = new List<string>();
            //ClassifyPnData.PNListDataLoad(ref data);    //加载待分类的PN

            //AttentionPnData.AttentionPnData_Pn_DELETE("yoma");
            int a = 0;
            AttentionPnData.AttentionPnData_Project_SELECT("liebeskind", ref a);
        }

        private void Button10_Click(object sender, EventArgs e)
        {
            SG.CaveSGB2Action.BeginInvoke(null, null);
        }

        private void Button17_Click(object sender, EventArgs e)
        {
            SG.EntranceSGA.ScanCodeTimeout(3000);
        }

        private void Button19_Click(object sender, EventArgs e)
        {
            SG.EntranceSGA.ScanCodeTimeout(3000);
        }

        private void Button13_Click(object sender, EventArgs e)
        {
            SG.CaveSGA1.ScanCodeTimeout(3000);
        }

        private void Button15_Click(object sender, EventArgs e)
        {
            SG.CaveSGA3.ScanCodeTimeout(3000);
        }

        private void Button16_Click(object sender, EventArgs e)
        {
            SG.EntranceSGB.ScanCodeTimeout(3000);
        }

        private void Button18_Click(object sender, EventArgs e)
        {
            SG.EntranceSGB.ScanCodeTimeout(3000);
        }

        private void Button12_Click(object sender, EventArgs e)
        {
            SG.CaveSGB1.ScanCodeTimeout(3000);
        }

        private void Button11_Click(object sender, EventArgs e)
        {
            SG.CaveSGB2.ScanCodeTimeout(3000);
        }

        private void Button14_Click(object sender, EventArgs e)
        {
            SG.CaveSGB3.ScanCodeTimeout(3000);
        }

        private void GroupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void Button20_Click(object sender, EventArgs e)
        {
            //string USN = textBox1.Text;
            //clsInfoNameValue[] infoNameValues = new clsInfoNameValue[3];
            //string str = SFCSInterface.GetKeyInfoFromView(USN, ref infoNameValues);
            //foreach (var item in infoNameValues)
            //{
            //    if (item != null)
            //    {
            //        Log4Net.MsgInfo(item.InfoValue);
            //    }
            //}

            MySqlFunction.PacketData.DELETE_PacketData.Packet_Data_Delete("'" + textBox1.Text + "'");
        }

        private void TextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Button21_Click(object sender, EventArgs e)
        {
            //if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A2) == 1)
            //{
            //    //Caver.CaveA25.ProgrammeWarehousing(CTextCreate.GetRandomString(11, true, false, true, false, ""), CTextCreate.GetRandomString(11, true, false, true, false, ""));
            //}
            //else
            //{
            //    Log4Net.MsgInfo("A2模组运动中");
            //}
        }

        private void Button22_Click(object sender, EventArgs e)
        {
            //if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A2) == 1)
            //{
            //    //Caver.CaveA11.ProgrammeWarehousing(CTextCreate.GetRandomString(11, true, false, true, false, ""), CTextCreate.GetRandomString(11, true, false, true, false, ""));
            //    CPLCControl.LAD_SetDblCell(PLC.dDestination_A2, 1);
            //}
            //else
            //{
            //    Log4Net.MsgInfo("A2模组运动中");
            //}
        }

        private void Button23_Click(object sender, EventArgs e)
        {
            //CEigenvector cEigenvector = new CEigenvector(LINE.ZERO, "123", KCAndBF.One, Remark.ANSI, DenseMatrix.OfArray(new[,] { { 0.0 }, { 0 }, { 0 }, { 0 } }));
            //List<int> refer = Caver.SearchClassReference(ref cEigenvector);
            //foreach (var item in refer)
            //{
            //    Log4Net.MsgInfo(item);
            //}
        }

        private void Button24_Click(object sender, EventArgs e)
        {
            //if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A3) == 1)
            //{
            //    //Caver.CaveA31.ProgrammeWarehousing(CTextCreate.GetRandomString(11, true, false, true, false, ""), CTextCreate.GetRandomString(11, true, false, true, false, ""));
            //}
            //else
            //{
            //    Log4Net.MsgInfo("A2模组运动中");
            //}
        }

        private void Button26_Click(object sender, EventArgs e)
        {
            //if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A3) == 1)
            //{
            //    //Caver.CaveA32.ProgrammeWarehousing(CTextCreate.GetRandomString(11, true, false, true, false, ""), CTextCreate.GetRandomString(11, true, false, true, false, ""));
            //}
            //else
            //{
            //    Log4Net.MsgInfo("A2模组运动中");
            //}
        }

        private void Button25_Click(object sender, EventArgs e)
        {
            //if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A3) == 1)
            //{
            //    //Caver.CaveA33.ProgrammeWarehousing(CTextCreate.GetRandomString(11, true, false, true, false, ""), CTextCreate.GetRandomString(11, true, false, true, false, ""));
            //}
            //else
            //{
            //    Log4Net.MsgInfo("A2模组运动中");
            //}
        }

        private void Button27_Click(object sender, EventArgs e)
        {
            //if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A3) == 1)
            //{
            //    //Caver.CaveA34.ProgrammeWarehousing(CTextCreate.GetRandomString(11, true, false, true, false, ""), CTextCreate.GetRandomString(11, true, false, true, false, ""));
            //}
            //else
            //{
            //    Log4Net.MsgInfo("A2模组运动中");
            //}
        }

        private void Button28_Click(object sender, EventArgs e)
        {
            //if (CPLCControl.LAD_CheckCell(PLC.mHandBusy_A3) == 1)
            //{
            //    //Caver.CaveA35.ProgrammeWarehousing(CTextCreate.GetRandomString(11, true, false, true, false, ""), CTextCreate.GetRandomString(11, true, false, true, false, ""));
            //}
            //else
            //{
            //    Log4Net.MsgInfo("A2模组运动中");
            //}
        }

        private void Button9_Click(object sender, EventArgs e)
        {
            ProductCellData a = new ProductCellData();
            ProductCellData b = new ProductCellData();
            a.usn = "liebeskind"; a.usnInfo = new string[3] { "hirata", "mina", "hanna", }; a.bin = new string[1] { "likin" };
            b.usn = "liebeskind"; b.usnInfo = new string[3] { "hirata", "mina", "hanna", }; b.bin = new string[1] { "likin" };
            MySqlFunction.TrayCellDataList.TrayCellDataList_INSERT(a, b);
        }

        private void Button29_Click(object sender, EventArgs e)
        {
            string snb = "";
            MySqlFunction.TrayCellDataList.TrayCellDataList_SN_SELECT("liebeskind", ref snb);

            string sEig = "0,llll,1,1";
            MySqlFunction.TrayCellDataList.TrayCellDataList_Eigenvector_UPDATE("liebeskind", "hirata", ref sEig);
            Log4Net.MsgInfo(sEig);
        }

        private void Button30_Click(object sender, EventArgs e)
        {
            //CPLCControl.LAD_SetDblCell(PLC.dClassifyEntrance_SQRC_A, 1);
        }

        private void Button31_Click(object sender, EventArgs e)
        {
            //Log4Net.MsgInfo(CPLCControl.LAD_GetDblCell(PLC.dClassifyEntrance_SQRC_A));
        }

        private void Button32_Click(object sender, EventArgs e)
        {
            //AutoFuncion.ClassifyEntranceQRCodeDispose();
        }

        private void Button33_Click(object sender, EventArgs e)
        {
            //AutoFuncion.ClassifyEntranceSG();
            //SFCSDataDispose.SFCSControl_ConsistencyAsyn.BeginInvoke("FPW92654FWTMRK7AJ", "FPW92643FDUMRK7A4", AutoFuncion.SFCSControl_ConsistencyAsynCallbackA, SFCSDataDispose.SFCSControl_ConsistencyAsyn);
            //XmlOperater.WriteItemToXml(CaverBuffData.caverBuffDataFeilName, "CaverBuffData", "CaverA31", "Eigenvector", "PN", "Liebeskind");
        }

        private void Button34_Click(object sender, EventArgs e)
        {
            //AutoFuncion.ClassifyCaveSG1();

        }

        private void Button35_Click(object sender, EventArgs e)
        {
            //AutoFuncion.ClassifyCaveSG1QRCodeDispose();
        }

        private void Button36_Click(object sender, EventArgs e)
        {
            //AutoFuncion.ClassifyCaveSG1PutStorage();
        }

        private void Button37_Click(object sender, EventArgs e)
        {
            SG.CaveSGA1.ScanCodeTimeout(SG.Timeout);
            SG.CaveSGA1ing = true;
        }

        private void Button38_Click(object sender, EventArgs e)
        {
            SG.EntranceSGACRCode = "FPW92654FWTMRK7AJ";
            bool Cons = false; string message = "";
            ProductCellData Cell1 = new ProductCellData() { usn = "", usnInfo = new string[20], bin = new string[10] };
            ProductCellData Cell2 = new ProductCellData() { usn = "", usnInfo = new string[20], bin = new string[10] };
            //SFCSDataDispose.SFCSControl_Consistency(ref SG.EntranceSGA1CRCode, ref SG.EntranceSGA2CRCode, ref Cons, ref message, ref Cell1, ref Cell2);           //盘内对比  
            //Log4Net.MsgInfo(Cell1.usnInfo[0] + "/" + Cell1.usnInfo[1]);
            //Log4Net.MsgInfo(".");
            //Log4Net.MsgInfo(Cell2.usnInfo[0] + "/" + Cell2.usnInfo[1]);


            //SFCSDataDispose.SFCSControl_ConsistencyAsyn.BeginInvoke(SG.EntranceSGA1CRCode, SG.EntranceSGA2CRCode, AutoFuncion.SFCSControl_ConsistencyAsynCallbackA, SFCSDataDispose.SFCSControl_ConsistencyAsyn);
        }

        private void Button39_Click(object sender, EventArgs e)
        {
            CPLCControl.LAD_SetDblCell(Caver.CaveA21.CaveStuation_PLC, 0);
        }

        private void Button40_Click(object sender, EventArgs e)
        {

        }

        private void Button41_Click(object sender, EventArgs e)
        {

        }

        private void Button42_Click(object sender, EventArgs e)
        {

        }

        private void Button43_Click(object sender, EventArgs e)
        {
            SG.ExitSG.ScanCodeTimeout(SG.Timeout);
        }

        private void Button44_Click(object sender, EventArgs e)
        {
            //int a = 0;
            //Log4Net.MsgInfo(a);
            //a++;
            //NodeForm.nodeForm.NodeEntBStaText(a.ToString());
            //a++;
            //Log4Net.MsgInfo(a);
            //a++;
            //Log4Net.MsgInfo(a);
            //a++;
            //Log4Net.MsgInfo(a);
            //a++;
            //NodeForm.nodeForm.NodeEntBStaText(a.ToString());


            //SG.ExitSGQRCode = "";
            //SG.ExitSG.ScanCodeTimeout(SG.Timeout);
            //SG.ExitSGing = true;
            //Log4Net.MsgInfo("回流入口/分类区出口扫码");


            Merge.BLL.CaverForm.CaverForm caverForm = new Merge.BLL.CaverForm.CaverForm();
            caverForm.Show();
        }

        private void Button45_Click(object sender, EventArgs e)
        {
            //MySqlFunction.BufferUsndataProgramme.BufferUsndataProgramme_UPDATE(211, 1, "Liebeskind");
            //MySqlFunction.BufferUsndataProgramme.BufferUsndataProgramme_DELETE(211);

            //Log4Net.MsgInfo(BitConverter.GetBytes(System.Convert.ToString(4, 2))[0]);
            //Log4Net.MsgInfo("");
            //Log4Net.MsgInfo(BitConverter.GetBytes(4)[1]);
            //Log4Net.MsgInfo("");
            //Log4Net.MsgInfo(BitConverter.GetBytes(4)[2]);
            //Log4Net.MsgInfo("");


            //if (AutoFuncion.SensorBit(1))
            //{
            //    Log4Net.MsgInfo("Yes");
            //}
            //else
            //{
            //    Log4Net.MsgInfo("No");
            //}

            //int a = 4 >> 15 & 1;
            //Log4Net.MsgInfo(a);
            //a = 4 >> 3 & 1;
            //Log4Net.MsgInfo(a);
            //a = 4 >> 2 & 1;
            //Log4Net.MsgInfo(a);
            //a = 4 >> 1 & 1;
            //Log4Net.MsgInfo(a);
            //a = 4 >> 0 & 1;
            //Log4Net.MsgInfo(a);
            int a = 1000;
            MySqlFunction.PacketDataErasure.PacketDataErasure_INSERT("LL", a);
            MySqlFunction.PacketDataErasure.PacketDataErasure_INSERT("FF");

            List<MySqlFunction.PacketDataErasure.PacketDataErasureStruct> packetDataErasureStructList = new List<Commonality.DAL.MySQL.MySqlFunction.PacketDataErasure.PacketDataErasureStruct>();
            MySqlFunction.PacketDataErasure.PacketDataErasure_SELECT(ref packetDataErasureStructList);
        }

        private void Button46_Click(object sender, EventArgs e)
        {
            //SG.BackflowExitSGAciton.BeginInvoke(null, null);
            if (!SG.BackflowExitSGing&& !SG.BackflowExitAssSGing)
            {
                SG.BackflowExitSGQRCode = "";
                SG.BackflowExitAssSGQRCode = "";
                SG.BackflowExitSGAciton.BeginInvoke(null, null);
                SG.BackflowExitSGing = true;
                SG.BackflowExitAssSGing = true;
                Log4Net.MsgInfo("回流线出口扫码");
            }
        }

        private void Button47_Click(object sender, EventArgs e)
        {
            List<string> aa = new List<string>(15);
            List<string> bb = new List<string>();

            int a = aa.Count;
            int b = aa.Count;
        }

        private void Button48_Click(object sender, EventArgs e)
        {
            MySqlFunction.Table_ClearAction.BeginInvoke(MySqlFunction.TrayCellDataList.TabName, 2500, null, null);
            MySqlFunction.Table_ClearAction.BeginInvoke(MySqlFunction.PackageOrientation.TabName, 2500, null, null);
            MySqlFunction.Table_ClearAction.BeginInvoke(MySqlFunction.Node.TabName, 10000, null, null);
        }

        private void Button49_Click(object sender, EventArgs e)
        {

            for (int i = 0; i < 1000; i++)
            {
                MySqlFunction.InputStatistics.InputStatistics_INSERT(i);
            }
        }
    }
}
